package com.weic.manager.expert.controller;

import com.weic.manager.controller.BaseController;
import com.weic.manager.expert.service.ExpertServiceImpl;
import com.weic.manager.utils.WUtils;
import com.weic.manager.utils.WebUtils;
import com.weic.manager.vo.ExpertVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 专家模块
 */
@Controller
@RequestMapping(value = "/expert")
public class ExpertController extends BaseController {

    @Autowired
    ExpertServiceImpl expertServiceImpl;

    @RequestMapping(value = "/expert_list.html")
    public ModelAndView articleList(HttpServletRequest request , HttpServletResponse response){

        return new ModelAndView("/expert_list.html");
    }

    /**
     * 获取所有专家数据
     * @return
     */
    @RequestMapping(value = "/getTopExpert.json")
    public @ResponseBody Map<String,Object> getAllExpert(){
        List<ExpertVO> expertVOS = expertServiceImpl.selectTop(20);
        return genAjaxResponse(true,"请求成功！",expertVOS);
    }

    /**
     * 返回专家明细页面
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value = "/expertDetail.html")
    public ModelAndView expertDetail(HttpServletRequest request,HttpServletResponse response){
        String pk_expert = request.getParameter("pk_expert");
        request.setAttribute("pk_expert",pk_expert);
        if(!WUtils.isEmpty(WebUtils.getLoginInfo()) && !WUtils.isEmpty(WebUtils.getLoginInfo().getUserVO())){
            request.setAttribute("userVO",WebUtils.getLoginInfo().getUserVO());
        }
        return new ModelAndView("/expert_detail.jsp");
    }

    /**
     * 获取专家明细数据
     * @param request
     * @param response
     */
    @RequestMapping(value = "/getExpertDetail.json")
    public @ResponseBody Map<String, Object> getExpertDetail(HttpServletRequest request, HttpServletResponse response){
        String pk_expert = request.getParameter("pk_expert");
        if(null == pk_expert || "".equals(pk_expert)){
            //TODO 
        }
        ExpertVO expertVO = expertServiceImpl.selectByPrimaryKey(pk_expert);
        return genAjaxResponse(true,"请求成功",expertVO);
    }
}
